﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XsqTech.SmartOA.Dtos.XSPDto.FromDto;
using XsqTech.SmartOA.IService;
using XsqTech.SmartOA.Service.DTO;
using XsqTech.SmartOA.Service;
using XsqTech.SmartOA.Dtos.XSPDto.FormDto;

namespace XsqTech.SmartOA.Application.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService _baseMenu;

        public MenuController(IMenuService baseMenu)
        {
            _baseMenu = baseMenu;
        }
        /// <summary>
        /// 树行
        /// </summary>
        /// <returns></returns>
        [HttpGet("Tree")]
        public IActionResult MenuTree()
        {
            var data = _baseMenu.MenuRecursion();
            return Ok(data);
        }
        /// <summary>
        /// 菜单添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddFrom(MenuDto dto)
        {
            if (!ModelState.IsValid)
            {
                return Ok(new ResponseModel() { Code = State.数据未导入, Message = "数据未导入" });
            }
            var data = _baseMenu.AddMenu(dto);
            if (data.Count > 0)
            {
                return Ok(data);
            }
            else
            {
                return Ok(data);
            }
        }

        /// <summary>
        /// 菜单显示
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult MenuQuery(string? Name)
        {
            return Ok(_baseMenu.MenuQuery(Name));
        }
        /// <summary>
        /// 菜单删除（单删）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult MenuDelete(string id)
        {
            var data = _baseMenu.MenuDelete(id);
            return Ok(data);
        }
        /// <summary>
        /// 菜单删除（批删）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpDelete("all")]
        public IActionResult AllFormDelete(List<MenuDto> dto)
        {
            var data = _baseMenu.AllMenuDelete(dto);
            return Ok(data);
        }
        /// <summary>
        /// 菜单反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("id")]
        public IActionResult MenuQueryId(string id)
        {
            return Ok(_baseMenu.MenuQueryId(id));
        }
        /// <summary>
        /// 菜单修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult UpdateMenu(MenuDto dto)
        {
            var data = _baseMenu.UpdateMenu(dto);
            return Ok(data);
        }
    }
}
